package com.guchenbo.example.ds.array;

/**
 * Created by CreGu on 2016/5/25.
 */
public class ArrayApp {

    public static void main(String[] args) {
        long[] arr = new long[5];
        int element = 0;
        int i;
        long searchKey;

//        insert
        arr[0] = 11;
        arr[1] = 21;
        arr[2] = 51;
        arr[3] = 31;
        arr[4] = 100;
//        display
        for (i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
//        search
        searchKey = 51;
        for (i = 0; i < arr.length; i++) {
            if (searchKey == arr[i]) {
                break;
            }
        }
        System.out.println("searchKey:" + i);
//        delete
        searchKey = 31;
        for (i = 0; i < arr.length; i++) {
            if (searchKey == arr[i]) {
                break;
            }
        }
        System.out.println("delete searchKey:" + i);
        for (int j = i; j < arr.length - 1; j++) {
//           后面的覆盖前面的
            arr[j] = arr[j + 1];
        }
        for (i = 0; i < arr.length - 1; i++) {
            System.out.println(arr[i]);
        }
    }
}
